<!DOCTYPE HTML>
<#include "/common/spring.ftl" />
<#include "/common/reference.ftl"/>
<#include "/common/pagination.ftl"/>
<html>
    <head>
    </head>
    <body>
        
     <form action="" method="POST"  class="form-horizontal" role="form" id="notice">
     	<input type="hidden" id="id" name="id" ></input>
     	<input type="hidden" id="code" name="code" ></input>
		<div class="well form-horizontal">
			<div class="form-group">
				<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 mt10">
					<label for="" class="control-label">登录代码:</label>
					<div class="col-lg-8 col-sm-8 col-xs-8">
						<input type="text" class="form-control" placeholder="请输入登录代码" id="userCode" name="userCode" value="<#if userCode?if_exists>${userCode}</#if>">
					</div>
				</div>
				<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 mt10">
					<label for="" class="control-label">用户名称:</label>
					<div class="col-lg-8 col-sm-8 col-xs-8">
						<input type="text" class="form-control" placeholder="请输入用户名称" id="userName" name="userName" value="<#if userName?if_exists>${userName}</#if>">
					</div>
				</div>
				<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 mt10">
					<label for="" class="control-label"></label>
					<a href="javascript:void(0)" id="queryCustomer" class="btn btn-success">查询</a>
					<button type="button" onclick="searchInit()" id="resetBtn" class="btn btn-default ml10">重置</button>
				</div>
			</div>
		</div>
		<div id="showTips" style="text-align: left;">
			<span class="xd-err hide" style="font-size:16px;"><i></i>请选择要修改的用户</span>
		</div>
		<div style="text-align: right;">
			<a id="userAdd" class="btn btn-danger">新增用户</a>
			<a id="userUpdate" class="btn btn-primary ml10">修改用户</a>
			<a id="userDelete" class="btn btn-warning ml10">删除用户</a>
		</div>
		<div class="choose mt10">
			<div class="table-fixed">
				<table class="table table-bordered center">
					<colgroup>
					    <col style="width:5%;">
					    <col style="width:10%;">
					    <col style="width:10%;">
					    <col style="width:15%;">
					    <col style="width:20%;">
					    <col style="width:15%;">
					    <col style="width:10%;">
					    <col style="width:15%;">
				    </colgroup>
					<thead>
						<tr>
							<th>
								<input id="CheckBoxAll" type="checkbox" class="xd-checkbox hide">
							</th>
							<th>登录代码</th>
							<th>用户名称</th>
							<th>用户类型</th>
							<th>用户邮箱</th>
							<th>用户电话</th>
							<th>用户状态</th>
							<th>用户创建时间</th>
						</tr>
					</thead>
					<tbody id="content">
						<#if (userList??) && (userList?size>0)>
							<#list userList as item>
								<tr>
								    <td><div class="text-center"><input type="radio"  id="checkId" name="checkName"  value="${item.id!""}"  ></div></td>
									<td><input type="hidden"  id="codes" name="codes"  value="${item.userCode!""}"  >${item.userCode!""}</td>
									<td id="username">${item.userName!""}</td>
									<td>${item.userType!""}</td>
									<td>${item.userMail!""}</td>
									<td>${item.userPhone!""}</td>
									<td>${item.userStatus!""}</td>
									<td>${item.userCreateTime!""}</td>
								</tr>
							</#list>
						<#else>
							<tr>
								<td colspan="8"><p class="no-data">暂无数据</p></td>
							</tr>
						</#if>
					</tbody>
				</table>
			</div>
		</div>
		</form>
		<@pager pagination=page formId="notice"/>
		<script type="text/javascript">
			$(document).ready(function(){
				$('#userAdd').bind('click', function(){
					showUserData(1);
				});
				
				$('#queryCustomer').bind('click', queryCustomer);
				
				$('#userUpdate').bind('click', function(){
					showUserData(0);
				});
				
				$('#userDelete').bind('click', function(){
					showUserData(2);
				});
			});
			
			function searchInit(){
			$("#userCode").val("");
			$("#userName").val("");
			}
				
			function queryCustomer(){
				 document.getElementById('notice').action="${contextPath}/system/user/list_main.do";
 		  	 	 $('#notice').submit();
			}
			
			function resetMain(){
				window.location="main.do";
			}
			
			function showUserData(opationCode){
				if(opationCode === 1){
					toShowUser(0);
				}else if (opationCode === 2){
					var flag = true;
					$("#content").find("tr").each(function(){
				 		if($(this).find(":radio").is(":checked")){
				 			var id = $(this).find(":radio").val();
				 			var code = $(this).find(":hidden").val();
				 			var username = $(this).find("#username").html();
				 			if("admin" == username ) {
				 				flag = false;
				 				alert("系统管理员不能被删除！");
				 				return false;
				 			}
				 			$("#id").val(id);
				 			$("#code").val(code);
				 			flag = false;
				 			document.getElementById('notice').action="${contextPath}/system/user/physicsdeleteuser.do?";
				 		    if(confirm("确定删除该用户吗？")){
				 					
				 					$('#notice').submit();
				 				}else{
				 					return false;
				 					 
				 				}
				 			
				 		}
			 		});
					if(flag){
						
						$("#showTips").find(".xd-err").html("请选择要删除的用户").show();
						$("#showTips").find(".xd-err").removeClass('hide');
						
					}
				}
				else{
					var flag = true;
					$("#content").find("tr").each(function(){
				 		if($(this).find(":radio").is(":checked")){
				 			$("#showTips").find(".xd-err").hide();
				 			var userId = $(this).find(":radio").val();
				 			flag = false;
				 			toShowUser(userId);
				 		}
			 		});
					if(flag){
						$("#showTips").find(".xd-err").html("请选择要修改的用户").show();
						$("#showTips").find(".xd-err").removeClass('hide');
					}
				}
			}
			
			function toShowUser(userId){
				var o = "";
				if(0 === userId){
					o = "新增";
				}else{
					o = "更改";
				}
				layer.open({ 
					type: 2,
					title: o+'用户',
					maxmin: false, //是否全屏
					shadeClose: true, 
					area : ['472px' , '352px'],//弹层的尺寸大小
					content: '${contextPath}/system/user/getuserbyuserid.do?userId='+userId
				});
			}
			
			/**
             * 回调操作
             */
            function afterOperation(data){
                if (data.errorMsg != ""){
                    showTips("MSG732",[data.errorMsg],tipType[0]);
                }else{
                    showTips("MSG120",["用户操作"],tipType[2]);
                }
            }
            
		</script>
    </body>
</html> 